<?php
namespace App\Admin\Controllers\Traits\WxSettingTraits;

use App\Admin\Renderable\IconRender;
use App\Admin\Renderable\PostRender;
use App\Admin\Renderable\TagRender;
use App\Admin\Renderable\UsersRender;
use App\Models\Posts\WxPost;
use App\Models\Posts\WxTag;
use App\Models\User\WxUser;
use App\Models\WxIcon;
use App\Models\WxUniversity;
use App\Wen\Utils\AdminUtils;
use App\Wen\Utils\FieldUtils;
use App\Wen\Utils\GatewayUtils;
use App\Wen\Utils\Settings;
use App\Wen\Utils\SiteUtils;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Widgets\Tooltip;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

trait formPagePublishTrait{
    public function index_publish(Content $content)
    {
        return $content->title('发布配置')
//            ->body($this->buildPreviewButton())
//            ->body($this->newline())
            ->body(
                <<<HTML
<div class="card">{$this->form_publish()->render()}</div>
HTML
            );
    }
    protected function form_publish(){
        $form = new Form();
        $form->confirm('您确定要提交表单吗？', 'content');
        $form->disableResetButton();
        $form->tab('弹窗', function (Form $form) {

            $form->row(function ($form) {
                $form->html(function () {
                    return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;display: inline-block;">提示：已登录的顶部提示<span style="color: red;">留空</span>，则代表关闭整个发布弹窗，直接跳转到发布页</div>';
                }, '');
            });

            $form->row(function ($form) {
                $form->html(function () {
                    return '';
                }, '<b>1、顶部提示</b>');
                $form->width(3)->text('uni_tabbar_popup_tip_1', '已登录')->help('[in_days]将会被替换该用户的在线天数，默认：今天是你加入宠也的第[in_days]天')->default(Settings::get('uni_tabbar_popup_tip_1', '', true));
                $form->width(3)->text('uni_tabbar_popup_tip_2', '未登录')->default(Settings::get('uni_tabbar_popup_tip_2', '请先登录', true));
            });
            $form->divider();

            $form->row(function ($form) {
                $form->html(function () {
                    return '';
                }, '<b>2、四个发布按钮</b>');
            });

            $form->row(function ($form) {
                $form->html(function () {
                    return '<img src="https://img.mini.minisns.cn/hbx/tabbar/bg/page_publish_1.jpg" style="width: 300px;" />';
                }, '');
            });


            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;display: inline-flex;width: 330px; text-align: center; justify-content: center;">①</div>';
            }, '')->width(2);
            $form->row(function ($form) {
                $form->width(2)->text('uni_tabbar_popup_1_text_1', '第一行')->default(Settings::get('uni_tabbar_popup_1_text_1', '发笔记/图文', true));
                $form->width(2)->text('uni_tabbar_popup_1_text_2', '第二行')->default(Settings::get('uni_tabbar_popup_1_text_2', '分享好玩的', true));
                $form->width(2)->text('uni_tabbar_popup_1_path', '路径')->help('怎么填请看<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>')->default(Settings::get('uni_tabbar_popup_1_path', '/pages/creat/index/creat', true));
            });
            $form->divider();

            $form->html(function () {
                return '<div style="width:330px;display: flex;justify-content: space-between;"><div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;display: inline-flex;width: 100px; text-align: center; justify-content: center;">②</div><div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;display: inline-flex;width: 100px; text-align: center; justify-content: center;">③</div><div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;display: inline-flex;width: 100px; text-align: center; justify-content: center;">④</div></div>';
            }, '')->width(2);
            $form->row(function ($form) {
                $form->width(2)->image('uni_tabbar_popup_2_icon', '②')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/hbx/tabbar/icon-img1.png" target="_blank">点击下载默认图</a>')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_popup_2_icon', 'https://img.mini.minisns.cn/hbx/tabbar/icon-img1.png', true));
                $form->width(2)->image('uni_tabbar_popup_3_icon', '③')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/hbx/tabbar/icon-img2.png" target="_blank">点击下载默认图</a>')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_popup_3_icon', 'https://img.mini.minisns.cn/hbx/tabbar/icon-img2.png', true));
                $form->width(2)->image('uni_tabbar_popup_4_icon', '④')->url('files/uploads')->help('<a href="https://img.mini.minisns.cn/hbx/tabbar/icon-img3.png" target="_blank">点击下载默认图</a>')->uniqueName()->autoUpload()->required()->default(Settings::get('uni_tabbar_popup_4_icon', 'https://img.mini.minisns.cn/hbx/tabbar/icon-img3.png', true));
            });
            $form->row(function ($form) {
                $form->width(2)->text('uni_tabbar_popup_2_text', '')->default(Settings::get('uni_tabbar_popup_2_text', '', true));
                $form->width(2)->text('uni_tabbar_popup_3_text', '')->default(Settings::get('uni_tabbar_popup_3_text', '', true));
                $form->width(2)->text('uni_tabbar_popup_4_text', '')->default(Settings::get('uni_tabbar_popup_4_text', '', true));
            });
            $form->row(function ($form) {
                $form->width(2)->text('uni_tabbar_popup_2_path', '路径')->help('怎么填请看<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>')->default(Settings::get('uni_tabbar_popup_2_path', '', true));
                $form->width(2)->text('uni_tabbar_popup_3_path', '路径')->help('怎么填请看<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>')->default(Settings::get('uni_tabbar_popup_3_path', '', true));
                $form->width(2)->text('uni_tabbar_popup_4_path', '路径')->help('怎么填请看<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>')->default(Settings::get('uni_tabbar_popup_4_path', '', true));
            });
            $form->divider();

            $form->row(function ($form) {
                $form->html(function () {
                    return '';
                }, '<b>3、创作灵感</b>');
            });
            $form->row(function ($form) {
                $form->html(function () {
                    return '<img src="https://img.mini.minisns.cn/hbx/tabbar/bg/page_publish_2.jpg" style="width: 300px;" />';
                }, '');
            });


            $form->row(function ($form) {
                $form->width(3)->text('uni_tabbar_popup_5_title', '标题')->default(Settings::get('uni_tabbar_popup_5_title', '创作灵感', true));
                $form->width(3)->text('uni_tabbar_popup_5_desc', '描述')->default(Settings::get('uni_tabbar_popup_5_desc', '大家都想看，跟着创作热度高', true));
            });
            $form->row(function ($form) {
                $form->width(6)->multipleSelectTable('uni_tabbar_popup_5_tags', '选择话题')
                    ->title('话题库')
                    ->max(3)
                    ->from(TagRender::make())
                    ->model(WxTag::class, 'id', 'tags_name', 'selectTable:formPagePublishTrait:uni_tabbar_popup_5_tags')
                    ->default(Settings::get('uni_tabbar_popup_5_tags', '', true));
            });
        });

        $form->tab('笔记', function (Form $form) {

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">位置一、底部第二行开闭</div>';
            }, '');
            $form->html(function (){
                return '<div> <img src="https://img.mini.minisns.cn/hbx/fixed_2.jpg" style="width: 200px;" /></div>';
            });
            $form->checkbox('app_publish_tools_fixed2_left', '左边按钮')->options(['location' => '添加位置', 'circle' => env('circle_call', '圈子')])->default(Settings::get('app_publish_tools_fixed2_left', ['location', 'circle'], true));
            $form->checkbox('app_publish_tools_fixed2_right', '右边按钮')->options(['pay' => '付费', 'anonymous'=>'匿名'])->default(Settings::get('app_publish_tools_fixed2_right', ['pay'], true));

            $form->html(function () {
                return '<div style="border: 2px dashed red; padding: 10px;">101:图片&nbsp;&nbsp;&nbsp;102:视频&nbsp;&nbsp;&nbsp;103:话题&nbsp;&nbsp;&nbsp;104:Gif&nbsp;&nbsp;&nbsp;105:表情&nbsp;&nbsp;&nbsp;106:更多&nbsp;&nbsp;&nbsp;107:@&nbsp;&nbsp;&nbsp;108:电话<br/>
201:音频&nbsp;&nbsp;&nbsp;202:投票&nbsp;&nbsp;&nbsp;203:商品&nbsp;&nbsp;&nbsp;204:附件&nbsp;&nbsp;&nbsp;205:链接&nbsp;&nbsp;&nbsp;206:第三方商品&nbsp;&nbsp;&nbsp;207:视频号&nbsp;&nbsp;&nbsp;208:闲置&nbsp;&nbsp;&nbsp;209:组局</div>';
            }, '');

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">位置二、底部倒数一行排列</div>';
            }, '');
            $form->html(function (){
               return '<div> <img src="https://img.mini.minisns.cn/images/publish/simple.jpg" style="width: 200px;" /></div>';
            });
            $form->text('app_publish_simple_fixed', '固定底部')->placeholder('101,102,103,104,105,106')->help('英文逗号隔开')->default(Settings::get('app_publish_simple_fixed', '101,102,103,104,105,106', true));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">位置三、底部弹窗排列</div>';
            }, '');
            $form->html(function (){
                return '<div> <img src="https://img.mini.minisns.cn/images/publish/simple2.jpg" style="width: 200px;" /></div>';
            });
            $form->text('app_publish_simple_popup', '底部弹窗')->placeholder('201,202,203,204')->help('英文逗号隔开')->default(Settings::get('app_publish_simple_popup', '201,202,203,204', true));

        });


        $form->tab('图文', function (Form $form) {
            $form->radio('app_publish_imagetext_switch', '发布图文')->options([0=>'关闭', 1=>'开启'])->default(Settings::get('app_publish_imagetext_switch', 1, true));
            $form->html(function () {
                return '<div style="border: 2px dashed red; padding: 10px;">301:段落&nbsp;&nbsp;&nbsp;302:图片&nbsp;&nbsp;&nbsp;303:视频&nbsp;&nbsp;&nbsp;304:链接&nbsp;&nbsp;&nbsp;305:音频&nbsp;&nbsp;&nbsp;306:表格&nbsp;&nbsp;&nbsp;307:撤回&nbsp;&nbsp;&nbsp;308:更多</div>';
            }, '');

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">位置一、固定底部</div>';
            }, '');
            $form->text('app_publish_imagetext_fixed', '固定底部')->placeholder('301,302,303,305,307,308')->help('英文逗号隔开')->default(Settings::get('app_publish_imagetext_fixed', '301,302,303,305,307,308', true));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">位置二、底部弹窗</div>';
            }, '');
            $form->html(function (){
                return '<div> <img src="https://img.mini.minisns.cn/images/publish/simple2.jpg" style="width: 200px;" /></div>';
            });
            $form->text('app_publish_imagetext_popup', '底部弹窗')->placeholder('304,306')->help('英文逗号隔开')->default(Settings::get('app_publish_imagetext_popup', '304,306', true));
        });

        $form->tab('提示', function (Form $form) {
            $form->textarea('app_publish_placeholder_text', '发笔记默认提示')->default(Settings::get('app_publish_placeholder_text', '分享我的笔记', true));
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ === 0){
                $form->switch('app_publish_success_popup', '发布成功弹窗')->default(Settings::get('app_publish_success_popup', 0) == 1 ? 1 : 0);
            }
        });

        $form->tab('媒体', function (Form $form) {
            $form->switch('app_upload_video_compress', '上传视频是否压缩')->help('压缩会牺牲画质，但减少空间，该配置仅对App生效，小程序内，微信默认会有压缩机制，需要你在相册选择的时候，勾选原图')->default(Settings::get('app_upload_video_compress', 1, true));
            $form->number('video_snapshot_time', 'App视频封面截第几秒')->default(Settings::get('video_snapshot_time', 3, true));
            $form->divider();
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">小提示: 你可以将此值设置为10000，则默认关闭该功能，因为图片应该达不到这么大的宽度</div>';
            }, '');
            $form->number('app_upload_image_max_width', '图片最大宽度')->help('如果用户上传的图片大于该宽度，则自动等比缩小到该宽度，后台上传的图片不影响。')->default(Settings::get('app_upload_image_max_width', 800, true));
            $form->rate('app_upload_image_slimming', '图片保存质量')->default(Settings::get('app_upload_image_slimming', 100, true));
        });
        $form->tab('付费', function (Form $form) {
            $form->number('app_pay_max_coins', '最大金币付费')->default(Settings::get('app_pay_max_coins', 10000, true));
            $res7 = __system__paycode__tip__(7);
            Tooltip::make('.mini_global_admin_open_not_support_tip')
                ->bottom()
                ->title($res7['tip']);
            $form->number('app_pay_max_balance', '最大余额付费')->help($res7['text'])->default(Settings::get('app_pay_max_balance', 1000, true));
        });

        $form->tab('限制', function (Form $form) {

            $form->radio('app_publish_permissions', '发布权限')->options(FieldUtils::userPermissions())->default(Settings::get('app_publish_permissions', 0, true));
            $form->number('app_publish_frequency_min', '距上次发布最小分钟')->default(Settings::get('app_publish_frequency_min', 10, true));
            $form->number('app_publish_times_max', '每天最多发布数量')->default(Settings::get('app_publish_times_max', 3, true));
            $form->radio('app_publish_circle_required', '必选'.env('circle_call', '圈子'))->options([0=>'非必选', 1=>'必选'])->default(Settings::get('app_publish_circle_required', 0, true));
            $form->radio('app_publish_media_required', '禁止纯文字笔记')->options([0=>'不禁止', 1=>'禁止'])->default(Settings::get('app_publish_media_required', 0, true));
            $form->radio('app_publish_force_bind_phone', '强制绑定手机号')->options([0=>'不强制', 1=>'强制'])->default(Settings::get('app_publish_force_bind_phone', 0, true));
            $form->radio('app_publish_force_real_name', '强制实名')->options([0=>'不强制', 1=>'强制'])->default(Settings::get('app_publish_force_real_name', 0, true));
            global $__MINI_GLOBAL_TENANT_ID__;
            $form->radio('app_publish_force_subscribe_mp', '强制关注公众号')->options([0=>'不强制', 1=>'强制'])->help($__MINI_GLOBAL_TENANT_ID__ > 0 ? '必须开启服务器地址' : '必须开启服务器地址，具体请去[全局配置-支付-微信-公众号]')->default(Settings::get('app_publish_force_subscribe_mp', 0, true));

            $form->multipleSelect('app_publish_force_university', '强制学生认证')->options(function ($sids) {
                if($sids){
                    $res = ['-1'=>'全域'];
                    foreach ($sids as $sid){
                        $university = WxUniversity::where('sid', $sid)->first();
                        if ($university) {
                            $res[$university->sid] = $university->name;
                        }
                    }
                    return $res;
                }else{
                    return ['-1'=>'全域'];
                }
            })->placeholder('请输入学校名字进行搜索')->ajax('select/universities')->default(Settings::get('app_publish_force_university', [], true));

            $form->html(function () {
                return '';
            }, '<b>上传</b>');
            $form->number('app_upload_max_files', '最大上传附件数')->help('不包活图片，仅指附件形式的等')->default(Settings::get('app_upload_max_files', 5, true));
            $form->number('app_upload_max_size_files', '单个附件最大（单位M）')->help('默认10M，这里每次更改，都需要重新更新前端才能生效')->default(Settings::get('app_upload_max_size_files', 10, true));
            $form->number('app_upload_max_sounds', '最大上传音频数')->default(Settings::get('app_upload_max_sounds', 1, true));
            //            $form->number('app_upload_max_imgs', '最大上传图片数')->default(Settings::get('app_upload_max_imgs', 9));
            $form->html(function () {
                return '';
            }, '<b>投票</b>');
            $form->number('app_vote_max_options', '最大投票选项数')->default(Settings::get('app_vote_max_options', 10, true));
            $form->html(function () {
                return '';
            }, '<b>二次编辑</b>');
            $form->number('app_publish_edit_need_coin', '二次编辑消耗金币')->default(Settings::get('app_publish_edit_need_coin', ($__MINI_GLOBAL_TENANT_ID__ > 0 ? Settings::get('app_publish_edit_need_coin', 100) : 100),  true));
        });
        $form->tab('水印', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">特别注意：<br/>1、后台上传的图片不会处理<br/>2、这种方式处理之后，查看原图，列表页等所有场景都会存在水印，且需要php安装imagemagick扩展（记得重启PHP）<br/>3、水印和图片之间是相对大小的，也就是说，系统会根据图片的大小做对应的调整，使整体看起来，水印都占比一样大</div>';
            }, '');
            $form->radio('app_upload_image_mask_type', '水印类型')->options([0=>'无', 1=> '图片', 2=>'文字(未开发)'])->when(1, function (Form $form){
                $form->rate('app_upload_image_mask_rate', '水印大小')->help('相对于上传的图片的百分比，然后对水印图片进行放缩到该大小，比如上传了很小的图片，水印也会相应的变小')->default(Settings::get('app_upload_image_mask_rate', 5, true));
                $form->rate('app_upload_image_mask_opacity', '水印透明度')->help('1-100')->default(Settings::get('app_upload_image_mask_opacity', 100, true));
                $form->text('app_upload_image_mask_img', '水印图片地址')->help('填例如: mask/mask.png，同时把水印文件上传到storage/mask目录下，点击查看<a href="https://img.mini.minisns.cn/images/hbx/mask_tip.jpg" target="_blank">教程图</a>')->default(Settings::get('app_upload_image_mask_img', '', true));
                $form->radio('app_upload_image_mask_pos', '水印位置')->options(['1'=>1, '2'=>2, '3'=>3, '4'=>4, '5'=>5, '6'=>6, '7'=>7, '8'=>8, '9'=>9])->help('1-9分包对应9个位置宫格，默认5代表中间')->default(Settings::get('app_upload_image_mask_pos', 5, true));
            })->default(Settings::get('app_upload_image_mask_type', 0, true));
        });
        $form->tab('选择话题', function (Form $form) {
            $form->html(function () {
                return '<a href="https://img.mini.minisns.cn/hbx/select_topic.jpg" target="_blank">点击查看，这里设置的是什么地方</a>';
            }, '');
            $form->multipleSelectTable('app_page_create_tags', '热门话题')
                ->title('话题库')
                ->max(10)
                ->from(TagRender::make())
                ->model(WxTag::class, 'id', 'tags_name', 'selectTable:formPagePublishTrait:app_page_create_tags')
                ->help('没有手动配置的情况下：如果捐助了<a href="https://ext.dcloud.net.cn/plugin?id=11115" target="_blank">【实时热榜】</a>，则使用实时热榜的数据，如果没有该付费模块，则按照话题引用累计总次数进行排序<a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')
                ->default(Settings::get('app_page_create_tags', '', true));
        });

        $form->tab('发布页2', function (Form $form) {
            $form->html(function () {
                return '<a href="https://img.mini.minisns.cn/images/mini/uni/971.jpg" target="_blank">点击查看，这里设置的是什么地方</a>';
            }, '');

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">一、背景</div>';
            }, '');

            $form->image('app_publish2_bg_img', '背景')->help('<a href="https://img.mini.minisns.cn/images/hbx/publish2-bg.jpg" download="app_share_vip_img.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->uniqueName()->url('files/uploads')->autoUpload()->default(Settings::get('app_publish2_bg_img', 'https://img.mini.minisns.cn/images/hbx/publish2-bg.jpg'));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">二、笔记展示</div>';
            }, '');

            $form->multipleSelectTable('app_publish2_post_show', '笔记展示')
                ->title('笔记库')
                ->max(10)
                ->from(PostRender::make())
                ->model(WxPost::class, 'id', 'id', 'selectTable:formPagePublishTrait:app_publish2_post_show')
                ->help('只能选择一个，<a href="'.admin_url('/posts/index').'" target="_blank">管理笔记库>></a><a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')
                ->default(Settings::get('app_publish2_post_show', '', true));

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">三、发布选项</div>';
            }, '');
            $form->multipleSelectTable('app_publish2_square_list', '发布选项')
                ->title('图标库')
                ->max(2)
                ->from(IconRender::make())
                ->model(WxIcon::class, 'id', 'name', 'selectTable:formPagePublishTrait:app_publish2_square_list')
                ->help('<a href="'.admin_url('settings/icons').'" target="_blank">管理图标库>></a><a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')
                ->default(Settings::get('app_publish2_square_list', '', true));
        });

        $form->tab('视频号', function (Form $form) {
            $form->multipleSelectTable('app_publish_post_sph_user', '视频号笔记发布员')
                ->title('用户')
                ->max(100)
                ->from(UsersRender::make())
                ->model(WxUser::class, 'id', 'user_name', 'selectTable:formPagePublishTrait:app_publish_post_sph_user')
                ->help('视频号发布用户设置，默认只允许管理员发布视频号笔记，但若你找了别人替你发布视频号笔记，可以这里增加，那么他的发布页就会显示 视频号 的功能')
                ->default(Settings::get('app_publish_post_sph_user', '', true));
        });

        $form->action('settings/action/publish');
        return $form;
    }

    public function publish(Request $request){
        global $__MINI_GLOBAL_TENANT_ID__;
        if(!_empty_($request->input('app_upload_image_mask_img')) && !file_exists(storage_path($request->input('app_upload_image_mask_img')))){
            return $this->response()->error('您配置的水印图片不存在！');
        }

        SiteUtils::forget_config_data();
        $tags = [];
        if($request->get('uni_tabbar_popup_5_tags')){
            $_5_tags = explode(',', $request->get('uni_tabbar_popup_5_tags'));
            if($_5_tags){
                $tags = WxTag::whereIn('id', $_5_tags)->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $_5_tags) . '"' . ")"))->limit(3)->get(['id', 'tags_name']);
                if($tags){
                    $tags = $tags->map(function ($v){
                        $v->path = '/pages/creat/index/creat?tag_id='.$v->id.'&tags_name='.$v->tags_name;
                        return $v;
                    });

                    $tags = $tags->toArray();
                }
            }
        }
        $popup_obj = [
            'tip' => [
                'login' => $request->input('uni_tabbar_popup_tip_1'),
                'nologin' => $request->input('uni_tabbar_popup_tip_2'),
            ],
            'button' => [
                'first' => [
                    'text1' => $request->input('uni_tabbar_popup_1_text_1'),
                    'text2' => $request->input('uni_tabbar_popup_1_text_2'),
                    'path' => $request->input('uni_tabbar_popup_1_path'),
                ],
                'second' => [
                    'icon' => $request->input('uni_tabbar_popup_2_icon'),
                    'text' => $request->input('uni_tabbar_popup_2_text'),
                    'path' => $request->input('uni_tabbar_popup_2_path'),
                ],
                'third' => [
                    'icon' => $request->input('uni_tabbar_popup_3_icon'),
                    'text' => $request->input('uni_tabbar_popup_3_text'),
                    'path' => $request->input('uni_tabbar_popup_3_path'),
                ],
                'fourth' => [
                    'icon' => $request->input('uni_tabbar_popup_4_icon'),
                    'text' => $request->input('uni_tabbar_popup_4_text'),
                    'path' => $request->input('uni_tabbar_popup_4_path'),
                ]
            ],
            'hot' => [
                'title' => $request->input('uni_tabbar_popup_5_title'),
                'desc' => $request->input('uni_tabbar_popup_5_desc'),
                'list' => $tags
            ]
        ];
        update_site_meta(_multi_key('app_publish_popup_config'), $popup_obj, 'j');

        Settings::set('uni_tabbar_popup_tip_1', $request->input('uni_tabbar_popup_tip_1'), true, true);
        Settings::set('uni_tabbar_popup_tip_2', $request->input('uni_tabbar_popup_tip_2'), true, true);
        Settings::set('uni_tabbar_popup_1_text_1', $request->input('uni_tabbar_popup_1_text_1'), true, true);
        Settings::set('uni_tabbar_popup_1_text_2', $request->input('uni_tabbar_popup_1_text_2'), true, true);
        Settings::set('uni_tabbar_popup_1_path', $request->input('uni_tabbar_popup_1_path'), true, true);

        Settings::set('uni_tabbar_popup_2_icon', $request->input('uni_tabbar_popup_2_icon'), true, true);
        Settings::set('uni_tabbar_popup_3_icon', $request->input('uni_tabbar_popup_3_icon'), true, true);
        Settings::set('uni_tabbar_popup_4_icon', $request->input('uni_tabbar_popup_4_icon'), true, true);

        Settings::set('uni_tabbar_popup_2_text', $request->input('uni_tabbar_popup_2_text'), true, true);
        Settings::set('uni_tabbar_popup_3_text', $request->input('uni_tabbar_popup_3_text'), true, true);
        Settings::set('uni_tabbar_popup_4_text', $request->input('uni_tabbar_popup_4_text'), true, true);

        Settings::set('uni_tabbar_popup_2_path', $request->input('uni_tabbar_popup_2_path'), true, true);
        Settings::set('uni_tabbar_popup_3_path', $request->input('uni_tabbar_popup_3_path'), true, true);
        Settings::set('uni_tabbar_popup_4_path', $request->input('uni_tabbar_popup_4_path'), true, true);

        Settings::set('uni_tabbar_popup_5_title', $request->input('uni_tabbar_popup_5_title'), true, true);
        Settings::set('uni_tabbar_popup_5_desc', $request->input('uni_tabbar_popup_5_desc'), true, true);
        Settings::set('uni_tabbar_popup_5_tags', AdminUtils::_multipleSelectTable_order_process('selectTable:formPagePublishTrait:uni_tabbar_popup_5_tags', $request->input('uni_tabbar_popup_5_tags')) , true, true);

        Settings::set('app_publish_tools_fixed2_left', $request->input('app_publish_tools_fixed2_left'), true, true);
        Settings::set('app_publish_tools_fixed2_right', $request->input('app_publish_tools_fixed2_right'), true, true);

        Settings::set('app_publish_simple_fixed', trim($request->input('app_publish_simple_fixed'), ','), true, true);
        Settings::set('app_publish_simple_popup', trim($request->input('app_publish_simple_popup'), ','), true, true);

        Settings::set('app_publish_imagetext_switch', trim($request->input('app_publish_imagetext_switch'), ','), true, true);
        Settings::set('app_publish_imagetext_fixed', trim($request->input('app_publish_imagetext_fixed'), ','), true, true);
        Settings::set('app_publish_imagetext_popup', trim($request->input('app_publish_imagetext_popup'), ','), true, true);


        Settings::set('app_upload_max_files', $request->input('app_upload_max_files'), true, true);
        Settings::set('app_upload_max_size_files', $request->input('app_upload_max_size_files'), true, true);
        Settings::set('app_upload_max_sounds', $request->input('app_upload_max_sounds'), true, true);
//        Settings::set('app_upload_max_imgs', $request->input('app_upload_max_imgs'), true);
        Settings::set('app_vote_max_options', _between_($request->input('app_vote_max_options'), 2, 20), true, true);

        Settings::set('app_publish_edit_need_coin', $request->input('app_publish_edit_need_coin'), true, true);



        Settings::set('video_snapshot_time', $request->input('video_snapshot_time'), true, true);
        Settings::set('app_upload_video_compress', $request->input('app_upload_video_compress'), true, true);
        Settings::set('app_upload_image_max_width', $request->input('app_upload_image_max_width'), true, true);
        Settings::set('app_upload_image_slimming', $request->input('app_upload_image_slimming'), true, true);

        // 水印
        Settings::set('app_upload_image_mask_type', $request->input('app_upload_image_mask_type'), true, true);
        Settings::set('app_upload_image_mask_opacity', $request->input('app_upload_image_mask_opacity'), true, true);
        Settings::set('app_upload_image_mask_rate', $request->input('app_upload_image_mask_rate'), true, true);
        Settings::set('app_upload_image_mask_img', $request->input('app_upload_image_mask_img'), true, true);
        Settings::set('app_upload_image_mask_pos', $request->input('app_upload_image_mask_pos'), true, true);

        Settings::set('app_publish_times_max', $request->input('app_publish_times_max'), true, true);
        Settings::set('app_publish_frequency_min', $request->input('app_publish_frequency_min'), true, true);

        Settings::set('app_pay_max_coins', $request->input('app_pay_max_coins'), true, true);
        Settings::set('app_pay_max_balance', $request->input('app_pay_max_balance'), true, true);

        Settings::set('app_publish_permissions', $request->input('app_publish_permissions'), true, true);
        Settings::set('app_publish_placeholder_text', $request->input('app_publish_placeholder_text'), true, true);

        if($__MINI_GLOBAL_TENANT_ID__ === 0){
            Settings::set('app_publish_success_popup', $request->input('app_publish_success_popup', 0) == 1 ? 1 : 0);
        }


        Settings::set('app_publish_circle_required', $request->input('app_publish_circle_required'), true, true);
        Settings::set('app_publish_media_required', $request->input('app_publish_media_required'), true, true);
        Settings::set('app_publish_force_bind_phone', $request->input('app_publish_force_bind_phone'), true, true);
        Settings::set('app_publish_force_real_name', $request->input('app_publish_force_real_name'), true, true);
        Settings::set('app_publish_force_subscribe_mp', $request->input('app_publish_force_subscribe_mp'), true, true);
        Settings::set('app_publish_force_university', $request->input('app_publish_force_university'), true, true);

        $force_university = $request->input('app_publish_force_university');
        if(_empty_(end($force_university))){
            array_pop($force_university);
        }
        if(!_empty_($force_university)){
            $str = '';
            foreach ($force_university as $sid){
                if(!_empty_($str)){
                    $str .= '、';
                }
                $str .= WxUniversity::where('sid', $sid)->value('name');
            }
            Settings::set('app_publish_force_university_tip', $str, true, true);
        }

        Settings::set('app_page_create_tags', AdminUtils::_multipleSelectTable_order_process('selectTable:formPagePublishTrait:app_page_create_tags', $request->input('app_page_create_tags')) , true, true);

        Settings::set('app_publish2_bg_img', $request->input('app_publish2_bg_img'), true, true);
        Settings::set('app_publish2_square_list', AdminUtils::_multipleSelectTable_order_process('selectTable:formPagePublishTrait:app_publish2_square_list', $request->input('app_publish2_square_list')) , true, true);
        Settings::set('app_publish2_post_show', AdminUtils::_multipleSelectTable_order_process('selectTable:formPagePublishTrait:app_publish2_post_show', $request->input('app_publish2_post_show')) , true, true);

        $app_publish_post_sph_user = AdminUtils::_multipleSelectTable_order_process('selectTable:formPagePublishTrait:app_publish_post_sph_user', $request->input('app_publish_post_sph_user'));
        Settings::set('app_publish_post_sph_user', $app_publish_post_sph_user, true, true);
        if(is_array($app_publish_post_sph_user)){
            $app_publish_post_sph_user = implode(',', $app_publish_post_sph_user);
        }
        _update_env([
            _multi_key('APP_PUBLISH_POST_SPH_USER') => $app_publish_post_sph_user,
        ], [], 1);

        $__global_config_version__ = Settings::get('__global_config_version__', 1) + 1;
        Settings::set('__global_config_version__', $__global_config_version__);
        GatewayUtils::success('all', 13, [ 'version' => $__global_config_version__, 'file' => basename(__FILE__) ]);
        return $this->response()->success('成功！');
    }

}
